{include file='common/head' /}
<script type="text/javascript" charset="utf-8" src="__PLURING__/jq.js"></script>
<!--百度编辑器-->
<script type="text/javascript" charset="utf-8" src="__UEDITOR__/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__UEDITOR__/ueditor.all.min.js"> </script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<style>
    #shareImg,#shareImg,#coverImg {
        padding:3px;
        border:1px solid #999;
        border-radius: 4px;
        max-width: 400px;
    }
</style>

<!-- 表情开始 -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<!-- Begin emoji-picker Stylesheets -->
<link href="__PLURING__/emoji/lib/css/nanoscroller.css" rel="stylesheet">
<link href="__PLURING__/emoji/lib/css/emoji.css" rel="stylesheet">
<!-- End emoji-picker Stylesheets -->
<!-- 表情结束 -->
<style>
    .upload-img {
        padding: 3px;
        border: 1px solid #999;
        border-radius: 4px;
        max-width: 400px;
    }
</style>
<script type="text/javascript" charset="utf-8" src="__UEDITOR__/lang/zh-cn/zh-cn.js"></script>
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form" lay-filter="example">
                    <input type="hidden" name="id" value="{$data.id}">
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            店铺名称
                        </label>
                        <div class="layui-col-md6">
                            <input type="text" name="name" autocomplete="off" class="layui-input" value="{$data.name}" data-emojiable="true">
                        </div>
                    </div>

                    <!-- 表情开始--- -->
                    <script src="__PLURING__/jq.js"></script>
                    <script>window.jQuery || document.write('<script src="js/jquery-2.1.1.min.js"><\/script>')</script>
                    <!-- Begin emoji-picker JavaScript -->
                    <script src="__PLURING__/emoji/lib/js/nanoscroller.min.js"></script>
                    <script src="__PLURING__/emoji/lib/js/tether.min.js"></script>
                    <script src="__PLURING__/emoji/lib/js/config.js"></script>
                    <script src="__PLURING__/emoji/lib/js/util.js"></script>
                    <script src="__PLURING__/emoji/lib/js/jquery.emojiarea.js"></script>
                    <script src="__PLURING__/emoji/lib/js/emoji-picker.js"></script>
                    <!-- End emoji-picker JavaScript -->
                    <script>
                    $(function() {
                      // Initializes and creates emoji set from sprite sheet
                      window.emojiPicker = new EmojiPicker({
                        emojiable_selector: '[data-emojiable=true]',
                        assetsPath: '/static/pluring/emoji/lib/img/',
                        popupButtonClasses: 'fa fa-smile-o'
                      });
                      // Finds all elements with `emojiable_selector` and converts them to rich emoji input fields
                      // You may want to delay this step if you have dynamically created input fields that appear later in the loading process
                      // It can be called as many times as necessary; previously converted input fields will not be converted again
                      window.emojiPicker.discover();
                    });
                      </script>
                    <!-- 表情结束--- -->
<!--                    真实姓名-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            真实姓名
                        </label>
                        <div class="layui-col-md6">
                            <input type="text" name="real_name" autocomplete="off" class="layui-input" value="{$data.real_name}">
                        </div>
                    </div>
<!--                    手机号码-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            手机号码
                        </label>
                        <div class="layui-col-md6">
                            <input type="text" name="phone" autocomplete="off" class="layui-input" value="{$data.phone}">
                        </div>
                    </div>
<!--                    身份证号码-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            身份证号码
                        </label>
                        <div class="layui-col-md6">
                            <input type="text" name="identity" autocomplete="off" class="layui-input" value="{$data.identity}">
                        </div>
                    </div>
                    {if isset($data) && $data && $data->getUserOne}
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            用户信息
                        </label>
                        <div class="layui-col-md9">
                            <p style="color: #00A2D4;margin-bottom: 6px;">&nbsp;&nbsp;&nbsp;&nbsp;{$data->getUserOne->nickname}</p>
                            <img style="height: 50px;width:50px;border-radius:25px;border:1px solid #999;"  src="{$data->getUserOne->avatarurl}" alt="用户头像">

                        </div>
                    </div>
                    {/if}
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            店铺logo
                        </label>
                        <div class="layui-input-block layui-upload">
                            <button type="button" class="layui-btn layui-btn-normal file" id="cover_img_btn"><i class="layui-icon"></i>上传图片</button>
                            <input class="layui-upload-file" type="file" accept="undefined" id="cover_img_file">
                            <span class="layui-inline layui-upload-choose">支持 png、jpg、jpeg 格式文件</span>
                        </div>
                        <div>
                            <img id="coverImg" class="img-circle" src="{$data.logo|default=''}" alt="请选择图片" />
                            <input type="hidden" name="logo" value="{$data.logo|default=''}" />
                        </div>
                    </div>
                    <!--                    身份证 正面-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            身份证正面
                        </label>
                        <div class="layui-input-block layui-upload">
                            <button type="button" class="layui-btn layui-btn-normal file" id="cardImgZhengMian_btn"><i class="layui-icon"></i>上传图片</button>
                            <input class="layui-upload-file" type="file" accept="undefined" id="cardImgZhengMian_file">
                            <span class="layui-inline layui-upload-choose">支持 png、jpg、jpeg 格式文件</span>
                        </div>
                        <div>
                            <img class="upload-img" id="cardImgZhengMian_img" src="{$data.card_img[0]|default=''}" alt="请选择图片" />
                            <input type="hidden" name="cardImgZhengMian_name" value="{$data.card_img[0]|default=''}" />
                        </div>
                    </div>
<!--                    身份证 反面-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            身份证反面
                        </label>
                        <div class="layui-input-block layui-upload">
                            <button type="button" class="layui-btn layui-btn-normal file" id="cardImgFanMian_btn"><i class="layui-icon"></i>上传图片</button>
                            <input class="layui-upload-file" type="file" accept="undefined" id="cardImgFanMian_file">
                            <span class="layui-inline layui-upload-choose">支持 png、jpg、jpeg 格式文件</span>
                        </div>
                        <div>
                            <img class="upload-img" id="cardImgFanMian_img" src="{$data.card_img[1]|default=''}" alt="请选择图片" />
                            <input type="hidden" name="cardImgFanMian_name" value="{$data.card_img[1]|default=''}" />
                        </div>
                    </div>
                    <!-- 营业执照-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            营业执照
                        </label>
                        <div class="layui-input-block layui-upload">
                            <button type="button" class="layui-btn layui-btn-normal file" id="certificate_photo_btn"><i class="layui-icon"></i>上传图片</button>
                            <input class="layui-upload-file" type="file" accept="undefined" id="certificate_photo_file">
                            <span class="layui-inline layui-upload-choose">支持 png、jpg、jpeg 格式文件</span>
                        </div>
                        <div>
                            <img class="upload-img" id="certificate_photo_img" src="{$data.certificate_photo|default=''}" alt="请选择图片" />
                            <input type="hidden" name="certificate_photo" value="{$data.certificate_photo|default=''}" />
                        </div>
                    </div>
                    <!--预热数-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            预热数
                        </label>
                        <div class="layui-col-md6">
                            <input class="layui-input" type="number" name="warm_number" placeholder="请输入内容" value="{$data.warm_number|default=''}"></input>
                        </div>
                    </div>
<!--                    是否开启-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            状态
                        </label>
                        <div class="layui-input-inline">
                            {if !isset($data['is_open'])}
                            <input type="radio" name="is_open" value="1" title="开启" checked>
                            <input type="radio" name="is_open" value="0" title="关闭">
                            {else /}
                            <input type="radio" name="is_open" value="1" title="开启" {if $data['is_open'] == 1}checked{/if}>
                            <input type="radio" name="is_open" value="0" title="关闭" {if $data['is_open'] == 0}checked{/if}>
                            {/if}
                        </div>
                    </div>
                    <!--                    审核状态-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            审核状态
                        </label>
                        <div class="layui-col-md6">
                            {if !isset($data['apply_status'])}
                            <input type="radio" name="apply_status" value="0" title="申请中" checked>
                            <input type="radio" name="apply_status" value="1" title="审核通过">
                            <input type="radio" name="apply_status" value="2" title="审核拒绝">
                            {else /}
                            <input type="radio" name="apply_status" value="0" title="申请中" {if $data['apply_status'] == 0}checked{/if}>
                            <input type="radio" name="apply_status" value="1" title="审核通过" {if $data['apply_status'] == 1}checked{/if}>
                            <input type="radio" name="apply_status" value="2" title="审核拒绝" {if $data['apply_status'] == 2}checked{/if}>
                            {/if}
                        </div>
                    </div>
<!--                    拒绝理由-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            拒绝理由
                        </label>
                        <div class="layui-col-md6">
                            <input class="layui-input" type="text" name="refuse_str" placeholder="请输入内容" value="{$data.refuse_str|default=''}"></input>
                        </div>
                    </div>
                    <!-- 店铺描述 -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            店铺描述
                        </label>
                        <div class="layui-col-md6">
                            <textarea name="desc"  placeholder="请输入内容" value="{$data.desc|default=''}" class="layui-textarea"></textarea>
                        </div>
                    </div>
<!--                    店铺详情-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            店铺详情
                        </label>
                        <div class="layui-input-block">
                            <script id="editor" type="text/plain" style="width:1024px;height:500px;"></script>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"></label>
                        <button class="layui-btn" lay-filter="add" lay-submit="">确定保存</button></div>
                </form>
            </div>
        </div>
        <script>
            var desc = "{$data.desc|default=''}";
        </script>
        <script>
            //实例化编辑器
            //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
            var ue = UE.getEditor('editor');
            window.onload=function(){
                //不设置页面延迟加载会报错
                setTimeout(function(){
                    UE.getEditor('editor').execCommand('insertHtml', '{$data.rule}');
                },2000);
            }

            layui.use(['form', 'layer','jquery','laydate'],function() {
                $ = layui.jquery;
                var form = layui.form,layer = layui.layer;
                form.val('example', {
                    desc
                });
                // var laydate = layui.laydate;
                // //日期时间选择器
                // laydate.render({
                //     elem: '#end_time'
                // });

                //监听提交
                form.on('submit(add)', function(data) {
                    var num = $('[lay-submit]').index($(this));
                    var formData = new FormData($('form')[num]);
                    // 更新时间戳
                    //formData.set('hours',Math.floor(new Date($("input[name=hours]").val()).getTime() / 1000))
                    //发异步，把数据提交给php
                    $.ajax({
                        url:"/admin/shop/list_edit",
                        type: "post",
                        data:formData,
                        dataType:"json",
                        cache: false,                      // 不缓存
                        processData: false,                // jQuery不要去处理发送的数据
                        contentType: false,                // jQuery不要去设置Content-Type请求头
                        success:function (res) {
                            if(res.code == 200){
                                layer.alert(res.msg, {icon: 1},function () {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                            }else{
                                layer.alert(res.msg, {icon: 5});
                            }
                        },
                        error:function(e){
                            layer.alert("网络错误", {icon: 5});
                        },
                    });
                    return false;
                });

                //图片阅览
                $('#cover_1').click(function(){
                    $('#cover').click();
                })

                $('#cover').change(function(e){
                    var imgBox = e.target;
                    var img = getObjectURL(imgBox.files[0]);
                    $('#cover_img').attr('src',img);
                });

                //图片阅览
                $('#test1').click(function(){
                    $('#test1s').click();
                })
                $('#test1s').change(function(e){
                    var imgBox = e.target;
                    var img = getObjectURL(imgBox.files[0]);
                    $('#img').attr('src',img);
                });

                //建立一個可存取到該file的url
                function getObjectURL(file) {
                    var url;
                    if (window.createObjectURL != undefined) { // basic
                        url = window.createObjectURL(file);
                    } else if (window.URL != undefined) { // mozilla(firefox)
                        url = window.URL.createObjectURL(file);
                    } else if (window.webkitURL != undefined) { // webkit or chrome
                        url = window.webkitURL.createObjectURL(file);
                    }
                    return url;
                }
                // logo图片上传
                uploadImgsInput("#cover_img_btn","#cover_img_file","#coverImg","logo","shop/user/logo");
                // 身份证 正面
                uploadImgsInput("#cardImgZhengMian_btn","#cardImgZhengMian_file","#cardImgZhengMian_img","cardImgZhengMian_name","shop/user/card")
                // 身份证 反面
                uploadImgsInput("#cardImgFanMian_btn","#cardImgFanMian_file","#cardImgFanMian_img","cardImgFanMian_name","shop/user/card")
                // 营业执照
                uploadImgsInput("#certificate_photo_btn","#certificate_photo_file","#certificate_photo_img","certificate_photo","shop/user/certificate")

                /*
                // 绑定 logo封面
                $("#cover_img_btn").click(function(){
                    $("#cover_img_file").click();
                })

                // 操作成功后的回调 - logo封面
                $('#cover_img_file').change(function(e){
                    var imgBox = e.target;
                    if(imgBox.files[0].size > 1024 * 1024 *2){
                        return layer.msg('失败，文件不得超过2mb',{icon: 5})
                    }
                    var img = getObjectURL(imgBox.files[0]);
                    $('#coverImg').attr('src',img);
                    var data = {image: imgBox.files[0]}
                    var formData = new FormData();
                    formData.append('image', imgBox.files[0]);
                    formData.append('prefix','activitys_cover');
                    ajaxFun('/admin/uploads/cosFiles','post',formData,function (res) {
                        $('input[name=cover]').val(res.data.url)
                    });
                });
                 */

                // 绑定 分享图片
                $("#share_img_btn").click(function(){
                    $("#share_img_file").click();
                })

                // 操作成功后的回调 - 活动封面
                $('#share_img_file').change(function(e){
                    var imgBox = e.target;
                    if(imgBox.files[0].size > 1024 * 1024 *2){
                        return layer.msg('失败，文件不得超过2mb',{icon: 5})
                    }
                    var img = getObjectURL(imgBox.files[0]);
                    $('#shareImg').attr('src',img);
                    var data = {image: imgBox.files[0]}
                    var formData = new FormData();
                    formData.append('image', imgBox.files[0]);
                    formData.append('prefix','activitys_share');
                    $.ajax({
                        url:"{:url('admin/uploads/cosFiles')}",
                        type: 'post',
                        async: false,
                        data: formData,
                        dataType: 'json',
                        processData: false,// 告诉jQuery不要去处理发送的数据
                        contentType: false,// 告诉jQuery不要去设置Content-Type请求头
                        beforeSend: function (){ //过程...
                        },
                        success: function (res) {
                            if (res.code == 200) {
                                layer.msg('加载成功', {icon: 6})
                                //$('input[name=img_url]').val(HOST_URL +'/' +  res.data.fileName + '/' + (res.data.prefix ? '/' +  res.data.prefix + '/' : '') + res.data.url.replace("\\",'/'))
                                //$('input[name=img]').val( (res.data.prefix ? '/' +  res.data.prefix + '/' : '') + res.data.url.replace("\\",'/'))
                                $('input[name=share]').val(res.data.url)
                            } else {
                                layer.msg(res.msg || '失败，麻烦重新尝试', {icon: 5})
                            }
                        },
                        error:function(){
                            layer.msg( '失败，重新尝试，多次失败后麻烦联系开发人员', {icon: 5})
                        }
                    })
                });

                // 绑定 详情图片
                $("#detailsImg_img_btn").click(function(){
                    $("#detailsImg_img_file").click();
                })

                // 操作成功后的回调 - 详情图片
                $('#detailsImg_img_file').change(function(e){
                    var imgBox = e.target;
                    if(imgBox.files[0].size > 1024 * 1024 *2){
                        return layer.msg('失败，文件不得超过2mb',{icon: 5})
                    }
                    var img = getObjectURL(imgBox.files[0]);
                    $('#detailsImg').attr('src',img);
                    var data = {image: imgBox.files[0]}
                    var formData = new FormData();
                    formData.append('image', imgBox.files[0]);
                    formData.append('prefix','activitys_details');
                    $.ajax({
                        url:"{:url('admin/uploads/cosFiles')}",
                        type: 'post',
                        async: false,
                        data: formData,
                        dataType: 'json',
                        processData: false,// 告诉jQuery不要去处理发送的数据
                        contentType: false,// 告诉jQuery不要去设置Content-Type请求头
                        beforeSend: function (){ //过程...
                        },
                        success: function (res) {
                            if (res.code == 200) {
                                layer.msg('加载成功', {icon: 6})
                                //$('input[name=img_url]').val(HOST_URL +'/' +  res.data.fileName + '/' + (res.data.prefix ? '/' +  res.data.prefix + '/' : '') + res.data.url.replace("\\",'/'))
                                //$('input[name=img]').val( (res.data.prefix ? '/' +  res.data.prefix + '/' : '') + res.data.url.replace("\\",'/'))
                                console.log(res.data.url)
                                $('input[name=detailsImg]').val(res.data.url)
                            } else {
                                layer.msg(res.msg || '失败，麻烦重新尝试', {icon: 5})
                            }
                        },
                        error:function(){
                            layer.msg( '失败，重新尝试，多次失败后麻烦联系开发人员', {icon: 5})
                        }
                    })
                });
            });
            // admin/uploads/cosFiles
        </script>

{include file='common/scroll' /}        
{include file='common/footer' /}